//
//  HEMemberViewController.m
//  huien
//
//  Created by yiban on 2017/5/31.
//  Copyright © 2017年 lcb. All rights reserved.
//

#import "HEMemberViewController.h"
#import "HEGestureManagerViewController.h"
#import "HECredentialsViewController.h"
#import "HECardInfoViewController.h"
#import "AppDelegate+HE.h"
#import "UserRestPWDViewController.h"
@interface HEMemberViewController ()<UITableViewDataSource,UITableViewDelegate,UIAlertViewDelegate>
{
    
}
@property(nonatomic,strong)LcbUITableView *lcbTableView;
@property(nonatomic,strong)NSMutableArray *cellArray;

@end

@implementation HEMemberViewController
@synthesize lcbTableView=_lcbTableView;
@synthesize cellArray=_cellArray;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navTitle = @"会员管理";
    if (!_cellArray) {
        _cellArray =[[NSMutableArray alloc] init];
    }
    _cellArray =[NSMutableArray arrayWithObjects:@"密码管理",@"手势密码",@"认证信息",@"银行卡管理",@"退出登录",nil];
    [self initTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)dealloc
{
    if (_lcbTableView) {
        [_lcbTableView removeFromSuperview];
        _lcbTableView=nil;
    }
    [LcbLog log:@"HEMemberViewController--------->dealloc"];
}
#pragma mark - tableview delegate
-(void)initTableView
{
    //
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 20, 60, 44);
    backButton.tag =100;
    [backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [backButton addTarget:self action:@selector(clickNavEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.headerView addSubview:backButton];
    //
    if (_lcbTableView) {
        [_lcbTableView removeFromSuperview];
        _lcbTableView=nil;
    }
    _lcbTableView =[[LcbUITableView alloc] initWithFrame:CGRectMake(0, YB_HeaderHeight, SCREEN_WIDTH, SCREEN_HEIGHT-YB_HeaderHeight) style:UITableViewStyleGrouped];
    _lcbTableView.dataSource=self;
    _lcbTableView.delegate=self;
    _lcbTableView.backgroundColor=[UIColor clearColor];
//    _lcbTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_lcbTableView];
}
-(void)clickNavEvent:(id)sender
{
    if (self.navigationController) {
        if (self.navigationController.viewControllers.count == 1) {
            [self.navigationController dismissViewControllerAnimated:YES completion:nil];
        } else {
            [self.navigationController popViewControllerAnimated:YES];
        }
    } else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _cellArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return LcbHEIGHT(40);
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (cell == nil) {
        cell = [[UITableViewCell  alloc]initWithStyle:UITableViewCellStyleDefault   reuseIdentifier:@"UITableViewCell"];
         cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    NSString *cellname =[self.cellArray objectAtIndex:indexPath.row];
    cell.textLabel.text=cellname;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellname =[self.cellArray objectAtIndex:indexPath.row];
    if ([cellname isEqualToString:@"密码管理"]) {
        UserRestPWDViewController *mPwd =[[UserRestPWDViewController alloc] init];
        [self.navigationController pushViewController:mPwd animated:YES];
        return;
    }else if ([cellname isEqualToString:@"手势密码"]) {
        HEGestureManagerViewController *message =[HEGestureManagerViewController newWithDelegate:nil];
        [self.navigationController pushViewController:message animated:YES];
        return;
    }else if ([cellname isEqualToString:@"认证信息"]) {
        HECredentialsViewController*cred =[[HECredentialsViewController alloc] init];
        [self.navigationController pushViewController:cred animated:YES];
        return;
    }else if ([cellname isEqualToString:@"银行卡管理"]) {
        HECardInfoViewController*cred =[[HECardInfoViewController alloc] init];
        [self.navigationController pushViewController:cred animated:YES];
        return;
    }else if ([cellname isEqualToString:@"退出登录"]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提醒" message:@"确定退出登录吗?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alert show];
        
        return;
    }
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex==1) {
        [HEShare logout:^(id obj) {}];
        [YBToast showWithText:@"退出登录"];
        [self.navigationController popToRootViewControllerAnimated:YES];
        AppDelegate * appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
        [appDelegate enterMainPage];
    }
}
@end
